<template>
  <div class="layer" v-if="show" @touchmove.stop="preventD">
    <div class="dialog">
      <div class="dialog-container">
        <h4 class="dialog-title" v-if="title">{{title}}</h4>
        <div class="dialog-content">
          <image class="dialog-content-avatar" v-if="avatar" :src="avatar"/>
          <div class="dialog-content-detail" v-if="content">
            <p v-for="(item, i) in content" :key="i">{{item}}</p>
          </div>
          <p v-if="tips" class="dialog-content-tip">{{tips}}</p>
          <m-buttton :openType="openType" :text="button" @onClick="onClick"></m-buttton>
        </div>
      </div>
      <icon v-if="showClose" type="cancel" size="30" color="#fff" @click="hideDialog"/>
    </div>
  </div>
</template>

<script>
import MButtton from 'comp/m-button'

export default {
  components: {
    MButtton
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    title: String,
    avatar: {
      type: String,
      default: ''
    },
    content: Array,
    tips: String,
    button: String,
    openType: String,
    showClose: {
      type: Boolean,
      default: true
    },
  },
  watch: {
    show (val) {
      val ? this.$emit('onShow') : this.$emit('onHide')
    }
  },
  methods: {
    preventD () {},
    hideDialog () {
      this.$emit('update:show', false)
    },
    onClick () {
      this.$emit('onClick')
      this.hideDialog()
    }
  }
}
</script>

<style lang="less" scoped>
.layer {
  z-index: 200;
  position: fixed;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, .5);
  .dialog {
    width: 100%;
    text-align: center;
    &-container {
      background: #fff;
      margin: 0 50rpx 60rpx;
      border-radius: 8rpx;
    }
    &-title {
      padding: 30rpx 0;
      font-size: 34rpx;
      color: #333;
      border-bottom: 1rpx solid #e6ebf0;
    }
    &-content {
      padding: 40rpx 40rpx;
      &-avatar {
        display: block;
        width: 100rpx;
        height: 100rpx;
        margin: 0 auto 30rpx auto;
      }
      &-detail {
        font-size: 32rpx;
        color: #333;
        line-height: 52rpx;
        margin-bottom: 40rpx;
      }
      &-tip {
        font-size: 28rpx;
        color: #777;
        margin-bottom: 40rpx;
      }
    }
  }
}
</style>
